<template>
	<ynet-content id="sysAuth" :headerInformation="true" :headerMenu="true">
        <div class="main-container">
			<ynet-breadcrumb></ynet-breadcrumb>
		</div>   
		<div class="main-container" >
            <template v-if="temp2">
                <div class="fourForm tableForm mt20">
                    <h3>Pending Task(s)</h3>
                    <el-table :data="bsnAuthList" border @selection-change="handleChange">
                        <!--<el-table-column label="选择" type="selection" ></el-table-column>-->
                        <el-table-column label="Transaction Sequence No." prop="flowNo" align="center">
                            <template scope="scope">
                                <el-button type="text" @click="openDetail(scope.$index,scope.row)"><p style="color:red;text-decoration:underline;">{{scope.row.flowNo}}</p></el-button>
                            </template>
                        </el-table-column>  
                        <el-table-column label="Transaction Type" prop="bsnName" align="center"></el-table-column>  
                        <el-table-column label="Action" prop="actionType" align="center">
                            <template scope="scope">
                                {{scope.row.actionType==0?"Add":scope.row.actionType==1?"Modify":scope.row.actionType==2?"Delete":""}}
                            </template>
                        </el-table-column>
                        <el-table-column label="Submit" prop="userAlias" align="center"></el-table-column>  
                        <el-table-column label="Submission Time" prop="submitTime" align="center">
                            <template scope="scope">
                                {{$tools.utils.formatDate(scope.row.submitTime,{"symbol":"YYYY-MM-DD HH:mm"})}}
                            </template>
                        </el-table-column>  
                    </el-table>
                </div>
                <div class="pagination tar mt20">
                    <el-pagination  @current-change="handleCurrentChange" :current-page="Number(queryForm.currentPage)" :page-size="Number(queryForm.turnPageShowNum)" layout="total, prev, pager, next, jumper" :total="Number(turnPageTotalNum)">
                    </el-pagination>
                </div>
                <!--
                <div class="btnArea mt20 tac">
                    <el-button type="primary" @click="agree()">Approve</el-button>
                    <el-button type="primary" @click="rules()">Reject</el-button>
                </div>
                -->
            </template>
            <!--拒绝页面弹窗-->
            <el-dialog :visible.sync="dialogTableVisible" :close-on-click-modal="false" :close-on-press-escape="false">
                <el-form ref="rejectForm" :model="rejectForm" class="formEmbedTable">
                    <table>
                        <caption>Refusal reason</caption>
                        <tr>
                            <td>Refusal reason</td>
                            <td>
                                <el-form-item prop="rejReason">
                                    <el-input placeholder="Refusal reason" v-model="rejectForm.rejReason"></el-input>
                                </el-form-item>
                            </td>
                        </tr>
                    </table>
                    <div class="btnArea mt20 tac">
                        <el-button type="primary" @click="dialogTableVisible = false,reject()">Confirm</el-button>
                    </div>
                </el-form>
            </el-dialog>
            <!--拒绝页面弹窗end-->
            <div>
                <!--详情页--> <!-- -->
                <RequestPinDetail v-if="IM0405" :detailData="detailData" :toDetail="toDetail" @back="back"></RequestPinDetail> <!-- 银行限额-->

                <BankLimitDetail v-if="IM0502" :detailData="detailData" :toDetail="toDetail" @back="back"></BankLimitDetail> <!-- 银行限额-->
                <AccLimitDetail v-if="IM0501" :detailData="detailData" :toDetail="toDetail" @back="back"></AccLimitDetail> <!-- 账号限额-->
                <AccStateChangeDetail v-if="IM040202" :detailData="detailData" :toDetail="toDetail" @back="back"></AccStateChangeDetail> <!-- 电话银行状态维护-->
                <addAndUnhookAccDetail v-if="IM040201" :detailData="detailData" :toDetail="toDetail" @back="back"></addAndUnhookAccDetail> <!-- 电话银行加解挂-->
                <newAccountDetail v-if="IM0401" :detailData="detailData" :toDetail="toDetail" @back="back"></newAccountDetail> <!-- 电话银行加解挂-->
            </div>
		</div>
	</ynet-content>
</template>

<script>
	import BankLimitDetail from './components/IM0502Detail';
    import AccLimitDetail from './components/IM0501Detail';
    import RequestPinDetail from './components/IM0405Detail';
    import AccStateChangeDetail from './components/IM040202Detail';
    import addAndUnhookAccDetail from './components/IM040201Detail';
    import newAccountDetail from './components/IM0401Detail';
	export default {
		name:'sysAuth',
		components:{
          BankLimitDetail,
          AccLimitDetail,
          RequestPinDetail,
          AccStateChangeDetail,
          addAndUnhookAccDetail,
          newAccountDetail,
		},
		data(){
            return {
                dialogTableVisible:false,turnPageTotalNum:'',
                IM0502:false,IM0501:false,IM0405:false,IM040202:false,IM040201:false,IM0401:false,
                authList:[],
                bsnAuthList:[],//某一菜单下待审核详情
                authInfoList:[],//待审核详情
                selectData:[],
                temp2:true,
                bsnCode:'',//菜单编号
                rejectForm:{//审核拒绝列表
                    bsnAuthList:[],authFlag:'1',rejReason:'',
                },
                agreeForm:{
                    bsnAuthList:[],authFlag:'0'
                },
                detailData:{},//传给详情页的对象
                toDetail:{},//传给详情页用来提交给后台的数据
                queryForm:{
                    currentPage:'1',turnPageShowNum:'10',bsnCode:'IM0302',
                },
            }   
        },
        mounted(){//从后台查询该用户待审核业务列表
             this.queryAuth()
        },
		methods:{ 
            handleCurrentChange(val) {//分页方法
                this.queryForm.currentPage=val;
                this.refreshAuthList()
            },
            queryAuth(){//打开某个单独菜单下的待审核信息
                //console.log("queryForm:"+JSON.stringify(this.queryForm))
                this.$tools.request(this,'IM0302QueryAction.do',this.queryForm).then(data=>{
                    console.log("待审核信息:"+JSON.stringify(data))
                    if(data.body.errorCode==0){
                        this.bsnAuthList=data.body.bsnAuthList;
                        this.turnPageTotalNum=data.body.turnPageTotalNum;
                    }else{
                        this.$alert("System Error Try again", "warning",{
                            confirmButtonText: 'Confirm',
                        })
                    }
                })
            },
            refreshAuthList(){//审核后刷新
                this.queryForm.bsnCode=this.bsnCode
                //console.log("form:"+JSON.stringify(this.queryForm))
                this.$tools.request(this,'IM0302QueryAction.do',this.queryForm).then(data=>{
                   //console.log("刷新:"+JSON.stringify(data))
                    if(data.body.errorCode==0){
                        this.bsnAuthList=data.body.bsnAuthList;
                        this.turnPageTotalNum=data.body.turnPageTotalNum;
                    }else{
                        this.$alert("System Error Try again", "warning",{
                            confirmButtonText: 'Comfirm',
                        })
                    }     
                })  
            },
            handleChange(newRow){
                //console.log(JSON.stringify(newRow))
                this.selectData=newRow;
                console.log("selectData:"+JSON.stringify(this.selectData))
            },
            back(){//返回审核页
                this.temp2=true;
                this.IM0405=false
                this.IM0502=false;
                this.IM0501=false;
                this.IM040202=false;
                this.IM040201=false;
                this.IM0401=false;
                //刷新审核页面
                this.refreshAuthList()
            },
            openDetail(index,row){//显示详情页
               var jsonData;
               let bsnCode=row.bsnCode;
               this.temp2=false; 
               this.toDetail=$.extend(this.toDetail,row)
               console.log("详情页toDetail:"+JSON.stringify(this.toDetail))
               for(let i=0;i<this.bsnAuthList.length;i++){
                   if(this.bsnAuthList[i].flowNo==row.flowNo){
                       jsonData=this.bsnAuthList[i].jsonStr;//json字符串
                       this.detailData=this.$tools.utils.transferJson(jsonData)
                       console.log("详情页具体:detailData:"+JSON.stringify(this.detailData))
                       break;
                   }
               }
               switch(bsnCode){
                   case 'IM0405': //银行限额
                    return this.IM0405=true;
                    case 'IM0502': //银行限额
                    return this.IM0502=true;
                    case 'IM0501': //账号限额
                    return this.IM0501=true;
                    case 'IM040202': //电话银行状态维护
                    return this.IM040202=true;
                    case 'IM040201': //电话银行加解挂
                    return this.IM040201=true;
                    case 'IM0401': //电话银行开户
                    return this.IM0401=true;
                }
            },
            agree(){
               //判断是否选中数据
               if(this.selectData.length==0){
                   this.$alert("select at least one",{
                        confirmButtonText: 'Confirm',
                    })
               }else{
                   this.agreeForm.bsnAuthList=this.selectData;
                   //console.log("selectData"+JSON.stringify(this.selectData))
                   console.log("agreeForm:"+JSON.stringify(this.agreeForm))
                    this.$tools.request(this,this.agreeForm.bsnAuthList[0].bsnCode+"AuthAction.do",this.agreeForm).then(data=>{
                        //console.log("data"+JSON.stringify(data))
                        if(data.body.errorCode==0){
                            this.$message({
                                type:'success',
                                message:'Success',
                                showClose:true,
                            })
                            this.refreshAuthList()
                        }else{
                            this.$alert("System Error Try again", "warning",{
                                confirmButtonText: 'Confirm',
                            })
                        }
                    })
               }
            },
            rules(){//判断是否选中数据
                if(this.selectData.length==0){
                    this.$alert("select at least one",{
                        confirmButtonText: 'Confirm',
                        callback: action => {
                        }
                    })
                }else{
                    this.dialogTableVisible=true;
                }
            },
            reject(){
                this.rejectForm.bsnAuthList=this.selectData;
                console.log("rejectForm:"+JSON.stringify(this.rejectForm))
                this.$tools.request(this,this.agreeForm.bsnAuthList[0].bsnCode+"AuthAction.do",this.rejectForm).then(data=>{
                    if(data.body.errorCode==0){
                         this.$message({
                            type:'success',
                            message:'Success',
                            showClose:true,
                        })
                        this.refreshAuthList()
                    }else{
                        this.$alert("System Error Try again", "warning",{
                            confirmButtonText: 'Confirm',
                        })
                    }
                })
            },
		}
	}
</script>